﻿using B.S.Procurement.Domain;
using B.S.Procurement.Domain.Extraction;
using B.S.Procurement.Domain.Sale;
using B.S.Procurement.Domain.SalesReturns;
using SqlSugar;

namespace B.S.Procurement.Infrastructure
{
    public class SCDBContext
    {
        public SqlSugarClient Db { get; }

        public SCDBContext()
        {
            Db = new SqlSugarClient(new ConnectionConfig()
            {
                DbType = DbType.MySql,
                ConnectionString = "server=123.57.166.20;port=3306;user=root;password=123456;database=text;",
                IsAutoCloseConnection = true,
                InitKeyType = InitKeyType.Attribute,
            });

            Db.DbMaintenance.CreateDatabase();
            Db.CodeFirst.InitTables(typeof(ProcurementModel));
            Db.CodeFirst.InitTables(typeof(Purchase));
            Db.CodeFirst.InitTables(typeof(PurchaseDetails));
            Db.CodeFirst.InitTables(typeof(VendorModel));
            Db.CodeFirst.InitTables(typeof(VendorTypeModel));
            Db.CodeFirst.InitTables(typeof(ProductsModel));
            Db.CodeFirst.InitTables(typeof(Client));
            Db.CodeFirst.InitTables(typeof(SaleModel));
            Db.CodeFirst.InitTables(typeof(Details));
            Db.CodeFirst.InitTables(typeof(ItemizedReturns));
            Db.CodeFirst.InitTables(typeof(SalesReturnsModel));
            Db.CodeFirst.InitTables(typeof(ExtractionModel));
            Db.CodeFirst.InitTables(typeof(ExtractionDetails));

            Db.Aop.OnLogExecuting = (sql, pars) =>
            {
                Console.WriteLine($"执行SQL:{sql},参数{sql}");
            };
        }
    }
}
